package com.zdkj.subway.st.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.st.entity.SwStStockDayCheckDetail;
import com.zdkj.subway.st.mapper.SwStStockDayCheckDetailMapper;
import com.zdkj.subway.st.service.SwStStockDayCheckDetailService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * @ProjectName: zdkj
 * @Package: com.zdkj.subway.st.service.impl
 * @ClassName: SwStStockDayCheckDetailServiceImpl
 * @Description:
 * @Author: kangjian
 * @CreateDate: 2020/1/19 10:56
 * @Version: 1.0
 */
@Service
@AllArgsConstructor
public class SwStStockDayCheckDetailServiceImpl extends ServiceImpl<SwStStockDayCheckDetailMapper, SwStStockDayCheckDetail> implements SwStStockDayCheckDetailService{

    @Autowired
    private SwStStockDayCheckDetailMapper stStockDayCheckDetailMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SwStStockDayCheckDetail entity) {
        PigxUser user = SecurityUtils.getUser();
        entity.setCreatorId(user.getId());
        entity.setCreatorName(user.getUsername());
        entity.setCreateTime(LocalDateTime.now());
        return super.save(entity);
    }

    @Override
    public int getOutStorgeNum(String TicketType, String StockArea) {
        Integer settleNum= stStockDayCheckDetailMapper.getOutStockNum(TicketType,StockArea);
        return settleNum==null?0:settleNum;
    }

    @Override
    public int getInStorgeNum(String TicketType, String StockArea) {
        Integer settleNum= stStockDayCheckDetailMapper.getInStockNum(TicketType,StockArea);
        return settleNum==null?0:settleNum;
    }

    @Override
    public int getSettleNum(String TicketType, String StockArea) {
       Integer settleNum= stStockDayCheckDetailMapper.getSettleNum(TicketType,StockArea);
       return settleNum==null?0:settleNum;
    }

    public int getNewSettleNum(String ticketName, String stockArea) {
        Integer settleNum= stStockDayCheckDetailMapper.getNewSettleNum(ticketName,stockArea);
        return settleNum==null?0:settleNum;
    }
}
